home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / Fade / Fade.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  11.1 KB  |  515 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.image.MemoryImageSource;
  14. import java.awt.image.PixelGrabber;
  15. import java.net.MalformedURLException;
  16. import java.net.URL;
  17. import java.net.URLEncoder;
  18.  
  19. public class Fade extends Applet implements Runnable, MouseListener {
  20.    // $FF: renamed from: n int
  21.    private int field_0;
  22.    // $FF: renamed from: m int
  23.    private int field_1;
  24.    private int tes;
  25.    // $FF: renamed from: wi int
  26.    private int field_2;
  27.    // $FF: renamed from: he int
  28.    private int field_3;
  29.    // $FF: renamed from: le int
  30.    private int field_4;
  31.    private int wiImage;
  32.    private int heImage;
  33.    private int decx;
  34.    private int decy;
  35.    private int wiBack;
  36.    private int heBack;
  37.    private int etapes = 50;
  38.    private int pause = 20;
  39.    private int nim = 2;
  40.    private int pause2 = 300;
  41.    private Thread thread;
  42.    // $FF: renamed from: b java.awt.Graphics
  43.    private Graphics field_5;
  44.    private Image current;
  45.    private Image buffer;
  46.    // $FF: renamed from: im java.awt.Image[]
  47.    private Image[] field_6;
  48.    private Image backImage;
  49.    private boolean loaded = false;
  50.    private boolean move = true;
  51.    private boolean isBackImage = false;
  52.    private Val[] tab;
  53.    // $FF: renamed from: pg java.awt.image.PixelGrabber
  54.    private PixelGrabber field_7;
  55.    private String[] image;
  56.    private String backImageName;
  57.    private String statusBarText;
  58.    private AudioClip sound;
  59.    private AudioClip clicSound;
  60.    private AudioClip enterSound;
  61.    private boolean loopSound;
  62.    private String link;
  63.    // $FF: renamed from: fm java.awt.FontMetrics
  64.    private FontMetrics field_8;
  65.    private String enterText;
  66.    private boolean isEnterTextEnabled;
  67.    private int wiEnterText;
  68.    private int enterTextHeight;
  69.    private Color enterTextColor;
  70.  
  71.    public String getAppletInfo() {
  72.       return "Name: Fade\r\nAuthor: Taiji Software\r\n";
  73.    }
  74.  
  75.    public Fade() {
  76.       ((Component)this).addMouseListener(this);
  77.    }
  78.  
  79.    public void register() {
  80.       try {
  81.          URL u = new URL("http://www.taijisoftware.com");
  82.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  83.       } catch (Exception e) {
  84.          System.out.println(e);
  85.          this.stop();
  86.       }
  87.    }
  88.  
  89.    public void init() {
  90.       String codeBase = null;
  91.  
  92.       try {
  93.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  94.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  95.          codeBase = codeBase.toUpperCase();
  96.       } catch (Exception var9) {
  97.       }
  98.  
  99.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  100.          String regCode = ((Applet)this).getParameter("registration_code");
  101.          if (regCode == null) {
  102.             regCode = ((Applet)this).getParameter("reg_domain");
  103.             if (regCode == null) {
  104.                this.register();
  105.             } else {
  106.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  107.                   codeBase = "WWW." + codeBase;
  108.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  109.                   codeBase = codeBase.substring(4);
  110.                }
  111.  
  112.                char[] chars = new char[codeBase.length()];
  113.                codeBase.getChars(0, codeBase.length(), chars, 0);
  114.                String key = new String("haricot");
  115.                char[] chars2 = new char[key.length()];
  116.                key.getChars(0, key.length(), chars2, 0);
  117.  
  118.                for(int i = 0; i < codeBase.length(); ++i) {
  119.                   int j;
  120.                   if (i >= key.length()) {
  121.                      j = i - key.length() * (i / key.length());
  122.                   } else {
  123.                      j = i;
  124.                   }
  125.  
  126.                   chars[i] += chars2[j];
  127.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  128.                }
  129.  
  130.                String res = new String(chars);
  131.                if (!res.equalsIgnoreCase(regCode)) {
  132.                   this.register();
  133.                }
  134.             }
  135.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  136.             this.register();
  137.          }
  138.       }
  139.  
  140.       this.move = true;
  141.       this.getParameters();
  142.       if (this.sound != null) {
  143.          if (this.loopSound) {
  144.             this.sound.loop();
  145.             return;
  146.          }
  147.  
  148.          this.sound.play();
  149.       }
  150.  
  151.    }
  152.  
  153.    public void getParameters() {
  154.       this.field_2 = ((Component)this).getSize().width;
  155.       this.field_3 = ((Component)this).getSize().height;
  156.       String s = ((Applet)this).getParameter("image_number");
  157.       if (s != null) {
  158.          this.nim = Integer.parseInt(s);
  159.       }
  160.  
  161.       this.image = new String[this.nim + 1];
  162.       this.backImageName = ((Applet)this).getParameter("background_image");
  163.       if (this.backImageName != null) {
  164.          this.isBackImage = true;
  165.       }
  166.  
  167.       ((Component)this).setBackground(this.getColor("background_color"));
  168.  
  169.       for(int i = 1; i <= this.nim; ++i) {
  170.          this.image[i] = ((Applet)this).getParameter("image" + i);
  171.       }
  172.  
  173.       s = ((Applet)this).getParameter("frame_number");
  174.       if (s != null) {
  175.          this.etapes = Integer.parseInt(s);
  176.       }
  177.  
  178.       s = ((Applet)this).getParameter("pause");
  179.       if (s != null) {
  180.          this.pause = Integer.parseInt(s);
  181.       }
  182.  
  183.       s = ((Applet)this).getParameter("pause2");
  184.       if (s != null) {
  185.          this.pause2 = Integer.parseInt(s);
  186.       }
  187.  
  188.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  189.       s = ((Applet)this).getParameter("sound_name");
  190.       if (s != null) {
  191.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  192.       }
  193.  
  194.       s = ((Applet)this).getParameter("loop_sound");
  195.       if (s != null) {
  196.          if (s.equals("yes")) {
  197.             this.loopSound = true;
  198.          } else {
  199.             this.loopSound = false;
  200.          }
  201.       }
  202.  
  203.       s = ((Applet)this).getParameter("clic_sound_name");
  204.       if (s != null) {
  205.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  206.       }
  207.  
  208.       s = ((Applet)this).getParameter("enter_sound_name");
  209.       if (s != null) {
  210.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  211.       }
  212.  
  213.       this.link = ((Applet)this).getParameter("link");
  214.       this.enterText = ((Applet)this).getParameter("enter_text");
  215.       s = ((Applet)this).getParameter("enter_text_height");
  216.       if (s != null) {
  217.          this.enterTextHeight = Integer.parseInt(s);
  218.       }
  219.  
  220.       this.enterTextColor = this.getColor("enter_text_color");
  221.       if (this.enterTextColor == null) {
  222.          this.enterTextColor = Color.white;
  223.       }
  224.  
  225.    }
  226.  
  227.    public Color getColor(String param) {
  228.       String s = ((Applet)this).getParameter(param);
  229.       if (s != null) {
  230.          if (s.substring(0, 1).equals("#")) {
  231.             s = s.substring(1);
  232.             int i = Integer.parseInt(s, 16);
  233.             return new Color(i);
  234.          } else {
  235.             return null;
  236.          }
  237.       } else {
  238.          return null;
  239.       }
  240.    }
  241.  
  242.    public final void paint(Graphics g) {
  243.       if (this.loaded) {
  244.          this.field_5.clearRect(0, 0, this.field_2, this.field_3);
  245.          if (this.isBackImage) {
  246.             this.field_5.drawImage(this.backImage, (this.field_2 - this.wiBack) / 2, (this.field_3 - this.heBack) / 2, this);
  247.          }
  248.  
  249.          this.field_5.drawImage(this.current, this.decx, this.decy, this);
  250.          if (this.isEnterTextEnabled) {
  251.             this.field_5.drawString(this.enterText, (this.field_2 - this.wiEnterText) / 2, this.field_3 / 2);
  252.          }
  253.  
  254.          g.drawImage(this.buffer, 0, 0, this);
  255.       }
  256.  
  257.    }
  258.  
  259.    public final void update(Graphics g) {
  260.       this.paint(g);
  261.    }
  262.  
  263.    public void start() {
  264.       if (this.thread == null) {
  265.          this.thread = new Thread(this);
  266.          this.thread.start();
  267.       }
  268.  
  269.    }
  270.  
  271.    public void stop() {
  272.       if (this.thread != null) {
  273.          this.move = false;
  274.          this.thread = null;
  275.       }
  276.  
  277.       if (this.sound != null) {
  278.          this.sound.stop();
  279.       }
  280.  
  281.    }
  282.  
  283.    public final void run() {
  284.       if (!this.loaded) {
  285.          this.field_6 = new Image[this.nim + 1];
  286.          MediaTracker tracker = new MediaTracker(this);
  287.  
  288.          for(int i = 1; i <= this.nim; ++i) {
  289.             this.field_6[i] = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.image[i]);
  290.          }
  291.  
  292.          for(int i = 1; i <= this.nim; ++i) {
  293.             tracker.addImage(this.field_6[i], 0);
  294.          }
  295.  
  296.          if (this.isBackImage) {
  297.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  298.             tracker.addImage(this.backImage, 0);
  299.          }
  300.  
  301.          try {
  302.             tracker.waitForAll();
  303.             this.loaded = !tracker.isErrorAny();
  304.          } catch (InterruptedException var12) {
  305.          }
  306.  
  307.          if (!this.loaded) {
  308.             this.stop();
  309.             return;
  310.          }
  311.       }
  312.  
  313.       this.wiImage = this.field_6[1].getWidth(this);
  314.       this.heImage = this.field_6[1].getHeight(this);
  315.       this.decx = (this.field_2 - this.wiImage) / 2;
  316.       this.decy = (this.field_3 - this.heImage) / 2;
  317.       if (this.isBackImage) {
  318.          this.wiBack = this.backImage.getWidth(this);
  319.          this.heBack = this.backImage.getHeight(this);
  320.       }
  321.  
  322.       this.buffer = ((Component)this).createImage(this.field_2, this.field_3);
  323.       this.field_5 = this.buffer.getGraphics();
  324.       this.field_5.setColor(this.enterTextColor);
  325.       String fontName = ((Applet)this).getParameter("enter_text_font");
  326.       if (fontName == null) {
  327.          fontName = "TimesRoman";
  328.       }
  329.  
  330.       int style = 1;
  331.       String s = ((Applet)this).getParameter("enter_text_style");
  332.       if (s != null) {
  333.          if (s.equals("bold")) {
  334.             style = 1;
  335.          } else if (s.equals("italic")) {
  336.             style = 2;
  337.          } else if (s.equals("bold_italic")) {
  338.             style = 3;
  339.          } else {
  340.             style = 0;
  341.          }
  342.       }
  343.  
  344.       this.field_5.setFont(new Font(fontName, style, this.enterTextHeight));
  345.       this.field_8 = this.field_5.getFontMetrics();
  346.       if (this.enterText != null) {
  347.          this.wiEnterText = this.field_8.stringWidth(this.enterText);
  348.       }
  349.  
  350.       this.field_4 = this.field_2 * this.field_3;
  351.       this.tab = new Val[this.nim + 1];
  352.  
  353.       for(int i = 1; i <= this.nim; ++i) {
  354.          this.tab[i] = new Val(this.field_4);
  355.       }
  356.  
  357.       this.tab[0] = new Val(this.field_4, 0);
  358.  
  359.       for(int i = 1; i <= this.nim; ++i) {
  360.          this.field_7 = new PixelGrabber(this.field_6[i], 0, 0, this.field_2, this.field_3, this.tab[i].pixels, 0, this.field_2);
  361.  
  362.          try {
  363.             this.field_7.grabPixels();
  364.          } catch (InterruptedException var11) {
  365.          }
  366.       }
  367.  
  368.       for(int j = 1; j <= this.nim; ++j) {
  369.          for(int i = 0; i < this.field_4; ++i) {
  370.             this.tab[j].blue[i] = this.tab[j].pixels[i] & 255;
  371.             this.tab[j].red[i] = this.tab[j].pixels[i] >> 16 & 255;
  372.             this.tab[j].green[i] = this.tab[j].pixels[i] >> 8 & 255;
  373.             this.tab[j].alpha[i] = this.tab[j].pixels[i] >> 24 & 255;
  374.          }
  375.       }
  376.  
  377.       Thread.currentThread().setPriority(1);
  378.       this.field_0 = 0;
  379.  
  380.       while(this.move) {
  381.          ++this.field_0;
  382.          if (this.field_0 > this.nim) {
  383.             this.field_0 = 1;
  384.          }
  385.  
  386.          if (this.field_0 < this.nim) {
  387.             this.field_1 = this.field_0 + 1;
  388.          }
  389.  
  390.          if (this.field_0 == this.nim) {
  391.             this.field_1 = 1;
  392.          }
  393.  
  394.          for(int i = 1; i <= this.etapes; ++i) {
  395.             switch (i) {
  396.                case 1:
  397.                   for(int j = 0; j < this.field_4; ++j) {
  398.                      this.tab[0].Blue[j] = (float)this.tab[this.field_0].blue[j];
  399.                      this.tab[0].Green[j] = (float)this.tab[this.field_0].green[j];
  400.                      this.tab[0].Red[j] = (float)this.tab[this.field_0].red[j];
  401.                   }
  402.             }
  403.  
  404.             for(int k = 0; k < this.field_4; ++k) {
  405.                float[] var10000 = this.tab[0].Blue;
  406.                var10000[k] += (float)(this.tab[this.field_1].blue[k] - this.tab[this.field_0].blue[k]) / (float)this.etapes;
  407.                var10000 = this.tab[0].Green;
  408.                var10000[k] += (float)(this.tab[this.field_1].green[k] - this.tab[this.field_0].green[k]) / (float)this.etapes;
  409.                var10000 = this.tab[0].Red;
  410.                var10000[k] += (float)(this.tab[this.field_1].red[k] - this.tab[this.field_0].red[k]) / (float)this.etapes;
  411.                this.tab[0].pixels[k] = this.tab[this.field_0].pixels[k] & -16777216 | (int)this.tab[0].Red[k] << 16 | (int)this.tab[0].Green[k] << 8 | (int)this.tab[0].Blue[k];
  412.             }
  413.  
  414.             this.current = ((Component)this).createImage(new MemoryImageSource(this.field_2, this.field_3, this.tab[0].pixels, 0, this.field_2));
  415.             ((Component)this).repaint();
  416.             System.gc();
  417.  
  418.             try {
  419.                Thread.sleep((long)this.pause);
  420.             } catch (InterruptedException var10) {
  421.                this.stop();
  422.             }
  423.          }
  424.  
  425.          try {
  426.             Thread.sleep((long)this.pause2);
  427.          } catch (InterruptedException var9) {
  428.             this.stop();
  429.          }
  430.       }
  431.  
  432.    }
  433.  
  434.    public URL giveURL(String url) {
  435.       try {
  436.          if (url.toUpperCase().startsWith("HTTP")) {
  437.             return new URL(url);
  438.          } else if (url.toUpperCase().startsWith("FTP")) {
  439.             int p = url.indexOf(":");
  440.             int p2 = url.indexOf(":", p + 1);
  441.             if (p2 != -1) {
  442.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  443.             }
  444.  
  445.             p = url.indexOf("%40");
  446.             if (p != -1) {
  447.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  448.             }
  449.  
  450.             return new URL(url);
  451.          } else {
  452.             return new URL(((Applet)this).getCodeBase(), url);
  453.          }
  454.       } catch (MalformedURLException e) {
  455.          System.out.println(e);
  456.          return null;
  457.       }
  458.    }
  459.  
  460.    public void mouseClicked(MouseEvent e) {
  461.    }
  462.  
  463.    public void mouseEntered(MouseEvent e) {
  464.       if (this.enterText != null) {
  465.          this.isEnterTextEnabled = true;
  466.          ((Component)this).repaint();
  467.       }
  468.  
  469.       if (this.statusBarText != null) {
  470.          ((Applet)this).showStatus(this.statusBarText);
  471.       }
  472.  
  473.       if (this.enterSound != null) {
  474.          this.enterSound.play();
  475.       }
  476.  
  477.       if (this.link != null) {
  478.          ((Component)this).setCursor(new Cursor(12));
  479.       }
  480.  
  481.    }
  482.  
  483.    public void mouseExited(MouseEvent e) {
  484.       if (this.isEnterTextEnabled) {
  485.          this.isEnterTextEnabled = false;
  486.          ((Component)this).repaint();
  487.       }
  488.  
  489.       if (this.link != null) {
  490.          ((Component)this).setCursor(new Cursor(0));
  491.       }
  492.  
  493.    }
  494.  
  495.    public void mousePressed(MouseEvent e) {
  496.       if (this.clicSound != null) {
  497.          this.clicSound.play();
  498.       }
  499.  
  500.       if (this.link != null) {
  501.          String target = ((Applet)this).getParameter("target");
  502.          if (target == null) {
  503.             target = "_blank";
  504.          }
  505.  
  506.          URL u = this.giveURL(this.link);
  507.          ((Applet)this).getAppletContext().showDocument(u, target);
  508.       }
  509.  
  510.    }
  511.  
  512.    public void mouseReleased(MouseEvent e) {
  513.    }
  514. }
  515.